import  java.util.EmptyStackException;
/**
 * 
 */

/**
 * A stack that can peek inside it's constants without changing the stack
 * @author Michael Fildestine ID:309161594
 *
 */
public class PeekableStackAsArray extends StackAsArray implements PeekableStack {
	
	public PeekableStackAsArray(){  //Constructor that builds StackAsArray object
		super();
	}
	
	public int size(){
		return super.size;
	}
	
	public Object peek(int i){
		Object ans;
		if (i < this.size && i >= 0){
			ans = this.elements[size - (i+1)]; 
			
		}else{
			throw new EmptyStackException();
		}
		return ans;
	}
	
	public String stackContents(){
		String ans ="";
		for (int i = size - 1 ; i >= 0 ; i--){
			ans = ans + this.elements[i].toString();
		}
		return ans;
	}
	
	public void clear(){
		this.size = 0;
	}

}
